
//
//  GTWeChatDynamicCell.m
//  GTW
//
//  Created by Ran on 15/11/12.
//  Copyright (c) 2015年 xcode. All rights reserved.
//

#import "GTWeChatDynamicCell.h"
#import "GTWeChatDynamicItemModel.h"
#import "GTWeChatDynamicTopView.h"
#import "GTWeChatDynamicContentView.h"
#import "GTWeChatDynamicImageContainerView.h"
#import "GTWeChatDynamicAtView.h"
#import "GTWeChatDynamicLinkView.h"
#import "GTWeChatDynamicTagView.h"
#import "GTWeChatDynamicLikeAndCommentView.h"

@interface GTWeChatDynamicCell()<GTWeChatDynamicContentViewDelegate>

@property(nonatomic, strong)GTWeChatDynamicTopView *topView;
@property(nonatomic, strong)GTWeChatDynamicContentView *contentContainerView;
@property(nonatomic, strong)GTWeChatDynamicImageContainerView *imageContainerView;
@property(nonatomic, strong)GTWeChatDynamicAtView *atView;
@property(nonatomic, strong)GTWeChatDynamicLinkView *linkView;
@property(nonatomic, strong)GTWeChatDynamicTagView *tagView;
@property(nonatomic, strong)GTWeChatDynamicLikeAndCommentView *likeAndLinkView;

@end

@implementation GTWeChatDynamicCell

#pragma mark - System

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

#pragma mark - Private

- (void)setupSubviews
{
    self.topView.frame = self.model.frameForTopView;
    [self.topView feedbackStoreData:self.model.dataForTopView];
    self.contentContainerView.frame = self.model.frameForContentView;
    [self.contentContainerView feedbackStoreData:self.model.dataForContentView];
    self.imageContainerView.frame = self.model.frameForImageContainerView;
    [self.imageContainerView feedbackStoreData:self.model.dataForImageContainerView];
    self.atView.frame = self.model.frameForAtView;
    [self.atView feedbackStoreData:self.model.dataForAtView];
    self.linkView.frame = self.model.frameForLinkView;
    [self.linkView feedbackStoreData:self.model.dataForLinkView];
    self.tagView.frame = self.model.frameForTagView;
    [self.tagView feedbackStoreData:self.model.dataForTagView];
}

#pragma mark - Delegate

- (void)contentViewHeightChanged:(GTWeChatDynamicContentView *)contentView
{
    [self.model loadData];
    if ([self.delegate respondsToSelector:@selector(cellHeightChanged:)]) {
        [self.delegate cellHeightChanged:self];
    }
}

#pragma mark - Setter

- (void)setModel:(GTWeChatDynamicItemModel *)model
{
    _model = model;
    [self setupSubviews];
}

#pragma mark - Getter

- (GTWeChatDynamicTopView *)topView
{
    if (!_topView) {
        self.topView = ({
            GTWeChatDynamicTopView *topView = [[GTWeChatDynamicTopView alloc] init];
            [self.contentView addSubview:topView];
            topView;
        });
    }
    return _topView;
}

- (GTWeChatDynamicContentView *)contentContainerView
{
    if (!_contentContainerView) {
        self.contentContainerView = ({
            GTWeChatDynamicContentView *contentContainerView = [[GTWeChatDynamicContentView alloc] init];
            contentContainerView.delegate = self;
            [self.contentView addSubview:contentContainerView];
            contentContainerView;
        });
    }
    return _contentContainerView;
}

- (GTWeChatDynamicImageContainerView *)imageContainerView
{
    if (!_imageContainerView) {
        self.imageContainerView = ({
            GTWeChatDynamicImageContainerView *imageView = [[GTWeChatDynamicImageContainerView alloc] init];
            [self.contentView addSubview:imageView];
            imageView;
        });
    }
    return _imageContainerView;
}

- (GTWeChatDynamicAtView *)atView
{
    if (!_atView) {
        self.atView = ({
            GTWeChatDynamicAtView *atView = [[GTWeChatDynamicAtView alloc] init];
            [self.contentView addSubview:atView];
            atView;
        });
    }
    return _atView;
}

- (GTWeChatDynamicLinkView *)linkView
{
    if (!_linkView) {
        self.linkView = ({
            GTWeChatDynamicLinkView *linkView = [[GTWeChatDynamicLinkView alloc] init];
            [self.contentView addSubview:linkView];
            linkView;
        });
    }
    return _linkView;
}

- (GTWeChatDynamicTagView *)tagView
{
    if (!_tagView) {
        self.tagView = ({
            GTWeChatDynamicTagView *tagview = [[GTWeChatDynamicTagView alloc] init];
            [self.contentView addSubview:tagview];
            tagview;
        });
    }
    return _tagView;
}

- (GTWeChatDynamicLikeAndCommentView *)likeAndLinkView
{
    if (!_likeAndLinkView) {
        self.likeAndLinkView = ({
            GTWeChatDynamicLikeAndCommentView *view = [[GTWeChatDynamicLikeAndCommentView alloc] init];
            [self.contentView addSubview:view];
            view;
        });
    }
    return _likeAndLinkView;
}

@end
